import QtQuick 2.0
import QtQuick.Controls 2.3

Item {
    id:root
    width: 850
    height: 580
    property real minSize:  Math.min(width/850, height/580)
    property real textSize:  40*minSize


    onFocusChanged: {
        if(!focus) return
//        listView.model.clear()
        listView_model.clear()
        report_time.text = (new Date).toLocaleString(Qt.locale(), "yyyy-MM-dd hh:mm:ss")
        var t_var = $sqlMcDefine.qml_queryTable2DRetVec1D("SELECT dec,define FROM reg_define WHERE define LIKE 'A套%'")
        for(var i=0; i<t_var.length/2;i++)
        {
            if(t_var[2*i]>4100)
            {
                var str = t_var[2*i+1]
                var sstr = str.split("A套")

                var stra = $sqlMcRecorder.qml_getRegulatorVal_bystr_toRealStr("A套"+sstr[1])
                var strb = $sqlMcRecorder.qml_getRegulatorVal_bystr_toRealStr("B套"+sstr[1])

//                var stra = $sqlMcRecorder.qml_getRegulatorVal_bystr_toint16("A套"+sstr[1])
//                var straa = $sqlMcRecorder.qml_getRegulatorVal_bystr_touint16("A套"+sstr[1])
//                var strb = $sqlMcRecorder.qml_getRegulatorVal_bystr_toint16("B套"+sstr[1])
//                var strbb = $sqlMcRecorder.qml_getRegulatorVal_bystr_touint16("B套"+sstr[1])
                listView.addModel(sstr[1], String(stra), String(strb))
            }
        }
    }

    Item {
        id: element
        x: 70*root.minSize
        width: 550*root.minSize
        height: parent.height

        Rectangle
        {
            id:toobarHeadertitle
            height: 25*root.minSize
            width:parent.width
            color: "#bbbbe2d8"

            Label {
                text: qsTr("1号机励磁系统调节器参数表")
                anchors.verticalCenter: parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
                font.bold: true
                font.family: "Tahoma"
                font.pixelSize: 17*root.minSize
                horizontalAlignment: Qt.AlignHCenter
                verticalAlignment: Qt.AlignVCenter
            }
        }

        Rectangle
        {
            id:toobarHeadertime
            height: 25*root.minSize
            width:parent.width
            anchors.top: toobarHeadertitle.bottom
            color: "#bbdbede8"

            Label {
                id:report_time
                text: qsTr("11")
                anchors.right: parent.right
                anchors.verticalCenter: parent.verticalCenter
                font.bold: true
                font.family: "Tahoma"
                font.pixelSize: 17*root.minSize
                horizontalAlignment: Text.AlignRight
                verticalAlignment: Qt.AlignVCenter
                Component.onCompleted: {
                    var date = new Date()
                    text = date.toLocaleString(Qt.locale(), "yyyy-MM-dd hh:mm:ss")
                }
            }

        }

        Rectangle
        {
            id:toobarHeader
            height: 25*root.minSize
            width:parent.width
            radius: height/4
            anchors.topMargin: 0
            anchors.top: toobarHeadertime.bottom
            color: "#bb5ed8b8"


            Label {
                id:label_factorName
                text: qsTr("参数名称")
                anchors.left: parent.left
                anchors.right: ts2.left
                font.bold: true
                font.family: "Tahoma"
                font.pixelSize: 17*root.minSize
                anchors.verticalCenter: parent.verticalCenter
                elide: Label.ElideRight
                horizontalAlignment: Qt.AlignHCenter
                verticalAlignment: Qt.AlignVCenter
            }
            ToolSeparator {
                id:ts2
                x:parent.width*0.40
                height: parent.height
                MouseArea{
                    height: parent.height
                    anchors.leftMargin: -width/2+parent.width/2
                    width: 50
                    anchors.left: parent.left
                    acceptedButtons: Qt.LeftButton //只处理鼠标左键
                    onPositionChanged: {
                        parent.x = mouseX+parent.x-width/2
                    }
                }
            }
            Label {
                id:label_channelA
                text: qsTr("A套参数值")
                anchors.left: ts2.right
                anchors.right: ts3.left
                font.bold: true
                font.family: "Tahoma"
                font.pixelSize: 17*root.minSize
                anchors.verticalCenter: parent.verticalCenter
                elide: Label.ElideRight
                horizontalAlignment: Qt.AlignHCenter
                verticalAlignment: Qt.AlignVCenter
            }
            ToolSeparator {
                id:ts3
                x:parent.width*0.72
                height: parent.height
                MouseArea{
                    height: parent.height
                    anchors.leftMargin: -width/2+parent.width/2
                    width: 50
                    anchors.left: parent.left
                    acceptedButtons: Qt.LeftButton //只处理鼠标左键
                    onPositionChanged: {
                        parent.x = mouseX+parent.x-width/2
                    }
                }
            }
            Label {
                id:label_channelB
                text: qsTr("B套参数值")
                anchors.left: ts3.right
                anchors.right: parent.right
                font.bold: true
                font.family: "Tahoma"
                font.pixelSize: 17*root.minSize
                anchors.verticalCenter: parent.verticalCenter
                elide: Label.ElideRight
                horizontalAlignment: Qt.AlignHCenter
                verticalAlignment: Qt.AlignVCenter
            }

        }


        ListView {
            id: listView
            clip: true
            width: parent.width
            anchors.top: toobarHeader.bottom
            anchors.bottom: parent.bottom
            snapMode: ListView.SnapToItem
            orientation:ListView.Vertical

            ScrollBar.vertical: ScrollBar {
                width: 25
                active: true
                anchors.right: parent.right
                parent: parent
            }

            model:ListModel{
                id:listView_model
            }

            delegate:Item {
                id: wrapper
                width: parent.width
                height: 30

                EXC_listViewItemDelegate2{
                    id: listViewItemdeleg_name
                    locationBase: label_factorName
                    mtext: text_name
                    textFontpointSize: 13*root.minSize
                }
                EXC_listViewItemDelegate2{
                    id: listViewItemdeleg_A
                    locationBase: label_channelA
                    mtext: text_factorA
                    textFontpointSize: 13*root.minSize
                }
                EXC_listViewItemDelegate2{
                    id: listViewItemdeleg_B
                    locationBase: label_channelB
                    mtext: text_factorB
                    textFontpointSize: 13*root.minSize
                }

                MouseArea {
                    id:mouseAreaThis
                    anchors.fill: parent
                    onClicked: listView .currentIndex = index
                    Rectangle{
                        anchors.fill: parent
                        border.width:1
                        border.color:wrapper.ListView.isCurrentItem?"lightskyblue":"transparent"

                        color:"transparent"
                    }
                }
            }

            Component.onCompleted: {
                for(var i=0;i<30;i++)
                addModel("1","2","3")
//                clearModel()
            }

            function addModel(name, a, b)
            {
                listView_model.append({
                                              "text_name":name,
                                              "text_factorA":a,
                                              "text_factorB":b
                                          });
            }
        }
    }

    EXC_Normal_BtnUncheckStyle {
        id: button3
        width: parent.width*0.15
        height: parent.height*0.09
        anchors.top: parent.top
        anchors.leftMargin: 680*root.minSize
        nameText: qsTr("返回")
        anchors.topMargin: 460*root.minSize
        nameFontpixelSize: 25*Math.min(root.width/850, root.height/580)
        anchors.left: parent.left
        onClicked: {
            sw.currentIndex = 0
        }
    }

    EXC_Normal_BtnUncheckStyle {
        id: button4
        width: parent.width*0.15
        height: parent.height*0.09
        anchors.top: parent.top
        anchors.leftMargin: 680*root.minSize
        nameText: qsTr("导出为表格")
        anchors.topMargin: 150*root.minSize
        nameFontpixelSize: 20*Math.min(root.width/850, root.height/580)
        anchors.left: parent.left
        onClicked:
        {
            var t_var = []
            t_var[0]=String("参数名称")+","
                    +String("A通道")+","
                    +String("B通道")
            for(var t=0; t<listView_model.count; t++)
                t_var[t+1]=String(listView_model.get(t).text_name)+","
                        +String(listView_model.get(t).text_factorA)+","
                        +String(listView_model.get(t).text_factorB)
            excRecordDisplayer.sl_selectCvs(t_var)
        }
    }

//    EXC_Normal_BtnUncheckSecret_programmerStyle {
//        id: button5
//        width: parent.width*0.15
//        height: parent.height*0.09
//        anchors.top: parent.top
//        anchors.leftMargin: 680*root.minSize
//        nameText: qsTr("打印预览")
//        anchors.topMargin: 230*root.minSize
//        nameFontpixelSize: 20*Math.min(root.width/850, root.height/580)
//        anchors.left: parent.left
//    }
}
